package com.xiaoshuidi.cloud.module.member.enums.point;

import cn.hutool.core.lang.Assert;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum PointTypeEnum {
    PLUS(1, "增加"),

    DEDUCTION(0, "扣减");

    private Integer code;
    private String name;

    public static String getNameByCode(Integer code) {
        PointTypeEnum pointTypeEnum = Arrays.stream(PointTypeEnum.values()).filter(p -> p.code.intValue() == code.intValue()).findFirst().orElse(null);
        Assert.isTrue(pointTypeEnum != null, "PointTypeEnum:{}不存在", code);
        return pointTypeEnum.getName();
    }
}
